#include <iostream>

template <typename T>
class Array {
private:
    T* arr;
    int size;
public:
    Array(int s) {
        size = s;
        arr = new T[size];
    }
    ~Array() {
        delete[] arr;
    }
    T& operator[](int i);
    fill(T val);
    front() {
        return arr[0];
    }
    back() {
        return arr[size-1];
    }
};


template <typename T>       //在类外定义函数模板，也需要加上模板关键字
T& Array<T>::operator[](int index) {    //此处<T>不可省略，表示模板类型参数，
    return arr[index];
}

template <typename T>
void Array<T>::fill(T val) {
    for (int i = 0; i < size; i++) {
        arr[i] = val;
    }
    std::cout << "Array filled with " << val << std::endl;
}


int main() {
    Array<int> arr(5);
    arr[0] = 10;
    arr[1] = 20;
    arr[2] = 30;
    arr[3] = 40;
    arr[4] = 50;
    for (int i = 0; i < 5; i++) {
        std::cout << arr[i] << " ";
    }
    std::cout << std::endl;
    return 0;
}